<?php

namespace App\Models;

use App\Common\Traits\HasAttachments;
use App\Common\Traits\HasValues;

class CommodityActivitySku extends Base
{
    use HasValues, HasAttachments;

    protected $table = 'commodity_activity_sku';

    public function commodityActivity()
    {
        return $this->belongsTo(CommodityActivity::class);
    }

    /**
     * 减少库存, 增加销量
     */
    public function decrementStockAndIncrementSales($num)
    {
        $this->increment('sales', $num);
        $this->decrement('stock', $num);
    }

    /**
     * 增加库存, 减少销量
     */
    public function incrementStockAndDecrementSales($num)
    {
        $this->decrement('sales', $num);
        $this->increment('stock', $num);
    }

    /**
     * 增加发货量
     * @param $shipment
     */
    public function incrementShipment($shipment)
    {
        $this->increment('shipment', $shipment);
    }
}
